<template>
    <div>
        <div class="login-content">
            <div class="input-content">
                <input type="text" autofocus v-model="code" placeholder="请扫描需要删除订单的二维码"  @keyup.enter="getCode">
                <!-- <button @click="getCode">提交</button> -->
            </div>
            <div class="btn-group">
                <mt-button size='large' type="danger" plain @click="scan()"> 扫描删除</mt-button>
                <mt-button size='large' type="danger" @click="()=>{$router.push('/boxIndex')}">订单装箱</mt-button>
            </div>
        </div>
    </div>
</template>
<script>
import {orderDel,wxSign} from '../api'
import {Toast} from 'mint-ui'
import cookie from '../cookie'
import wxScan from '../wxScan';
export default {
    data() {
        return {
            code:'',
            roleinfo:{}
        }
    },
    created(){
        this.roleinfo = JSON.parse(cookie.get('data','roleinfo'));
    },
    methods:{
        getCode(){
            const data = {
                order_no:this.code,
                token:cookie.get('data','token')
            }
            orderDel(data).then(res=>{
                if(res.code == 200){
                    Toast("删除成功");
                    this.code = "";
                }else{
                    Toast("删除失败,请查看订单是否已装箱");
                }
            })
        },
        scan(){
            const data = {
                token:cookie.get('data','token'),
                url:window.location.href.split('#')[0],
                id:this.roleinfo.id
            }
        //   console.log(data);
          wxSign(data).then(res=>{
              wxScan.wxRegister(res.data).then(res=>{
                this.code = res.resultStr;
                this.getCode();
              }).catch(err=>{
                Toast('扫描失败,请重试');
              })
          })
        }
    }
}
</script>
<style scoped>
    .btn-group{
        height: 6rem;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }
</style>